
import json

''' task packer'''
class requestParser:
    def __init__(self):
		self.json_r=""
	def parse(self,data):
		self.json_r =json.loads(data)
	def getCmd(self):
		return self.json_r.get('cmd') 
	def getData(self):
		return self.json_r.get('data')
#cmd: task_reqeust,task_response,status_response,result_response
class requestPacker:
    def __init__(self):
        self.json_data={}
    def packer(self,cmd,data):
        self.json_data['cmd'] = cmd
        self.json_data['data'] = data
    def getStrData(self):
        return json.dumps(self.json_data)
    def clear(self):
	self.json_data={}
class vulnPacker:
    def __init__(self):
	self.json_data={}
	self.list_data = []
    def packer(self,url,post,cveid,urlid,port,httprequest,httpresponse):
	self.json_data['url'] = url
	self.json_data['post'] = post
	self.json_data['cveid'] = cveid
	self.json_data['urlid'] = urlid
	self.json_data['port'] = port
	self.json_data['httprequest'] = httprequest
	self.json_data['httpresponse'] = httpresponse
	self.list_data.append(self.json_data)
    def getStrData(self):
	return self.list_data
    def clear(self):
	self.json_data={}
	self.list_data=[]
class statusPacker:
    def __init__(self):
	self.json_data = {}
	self.list_data =[]
    def packer(self,urls,callback,task_id,status):
	self.json_data['urls'] = urls
        self.json_data['task_id'] = task_id
	self.json_data['task_status'] = status
	self.json_data["callback"] = callback
	self.list_data.append(self.json_data)
    def getStrData(self):
	return self.list_data
    def clear(self):
	self.json_data={}
	self.list_data=[]


class taskPacker:
    def __init__(self):
	self.json_data={}
	self.task_list =[]
    def packer(self,task_type,urls,cookie,callback,task_id,speed,referer,port,siteid,urlid,crawl_depth,crawl_maxlink,domainid):
        self.json_data['urls'] = urls
	self.json_data['task_type'] = task_type
        self.json_data['cookie'] = cookie
	self.json_data["callback"] = callback
	self.json_data["task_id"] = task_id
	self.json_data["speed"] = speed
	self.json_data["plugInList"] =['Domjump.py','Domxss.py']
	self.json_data["referer"] = referer
	self.json_data["port"] = port
	self.json_data["siteid"] = siteid
	self.json_data["urlid"] = urlid
	self.json_data["crawl_depth"] = crawl_depth
	self.json_data["crawl_maxlink"] =crawl_maxlink
	self.json_data['domainid'] = domainid
	self.task_list.append(self.json_data)
    def getStrData(self):
	return self.task_list
    def getJsonData(self):
        return json.dumps(self.json_data)
    def clear(self):
	self.json_data ={}
	self.task_list =[]
class crawlTaskPacker:
    def __init__(self):
	self.json_data={}
    def pack(self,url,post,dtepth,maxlink,cookie):
	self.json_data['url'] = url
	self.json_data['post'] = post
	self.json_data['depth'] = depth
	self.json_data['maxlink'] = maxlink
	self.json_data['cookie'] = cookie
    def getStrData(self):
	return self.json_data
    def getJsonData(self):
	return json.dumps(self.json_data) 
class urlComposer:
    def __init__(self):
        self.urls = []
    def urlCompose(self,url,post,http_header,referer,url_id,port,tag="",domainid=""):
        dic = {}
        dic['url'] = url
        dic ['post'] = post
        dic['http_header'] = http_header
        dic['referer'] = referer
	dic['url_id'] =url_id
	dic['port'] = port
	dic['tag'] = tag
	dic['domainid'] = domainid
        self.urls.append(dic)
    def getUrls(self):
        return self.urls
    def clear(self):
        self.urls= []
